$(document).ready(
    function(){
        
        var UI = {};
        (function (UI) {
            
            UI.start = function(){
                
            };
            
        }(UI));
        var Helpers = {};
        (function (Helpers) {
            
            
        }(Helpers));
        
        var Actions = {};
        (function (Actions) {
            
            Actions.addBarsInsert = function(args) {
                var dfd = new $.Deferred();
                console.log("%c runSQL addBarsInsert", "color: green");
                $.ajax({
                    type: "POST",
                    url: "../resources/helpers/addBarsInsert.php",
                    data: args,
                    cache: false,
                    success: function(data){
                        console.log("%c Returned from addBarsInsert:","color: green");
                        console.log(data);
//                        data = JSON.parse(data);
//                        dfd.resolve(data);
                    }
                });
                return dfd.promise();
            };
            
            Actions.GetBarList = function(args) {
                var dfd = new $.Deferred();
                $.ajax({
                    type: "GET",
                    url: "../resources/helpers/addBarsGetBarList.php",
                    data: args,
                    cache: false,
                    success: function(data){
                        data = JSON.parse(data);
                        dfd.resolve(data);
                    }
                });
                return dfd.promise();
            };
            
        }(Actions));
        
        var Controller = {};
        (function (Controller) {
            function runSqlClicked(){
                var args ={
                    action          : "insert",
                    name            : $("#name").val(),
                    country         : 'Norway',
                    description     : $("#description").val(),
                    postal_no       : $("#postal_no").val(),
                    place           : $("#place").val(),
                    address         : $("#address").val(),
                    cover_charge    : $("#cover_charge").val(),
                    beer_price      : $("#beer_price").val(),
                    age_limit       : $("#age_limit").val(),
                    user_id         : '1',
                    status_id       : '1'
                };
                console.log(args);
                $.when(Actions.addBarsInsert(args)).then(
                    function(){

                    }
                );
            }
            
            Controller.init= function(){
                $("#register-bar-btn").unbind("click").bind("click", runSqlClicked);
            };
            
        }(Controller));	
        
        UI.start();
        Controller.init();
    }
);